<template>
	<view>
		<van-dialog id="van-dialog" :confirm-button-color="primaryColor"/>
		<!-- <van-cell :title="label" is-link :value="value" @click="onShowPanel" /> -->
		<van-field :label="label" :value="value"  input-align="right" @click-icon="onShowPanel" data-type="passengerName" @change="onChange" right-icon="location-o"
		  />
	</view>
</template>

<script>
	import Dialog from '@/wxcomponents/dialog/dialog';
	export default {
		props:{
			label: String,
			type: String,
			placeholder: String,
			currentAddress: String
		},
		data() {
			return {
				primaryColor:getApp().globalData.primaryColor,
				value: this.currentAddress || this.placeholder
			};
		},
		methods:{
			onChange(e){
				this.$emit('change', {
					detail: {address: e.detail},
					currentTarget: {
						dataset: {
							type: this.type
						}
					}
				})
			},
			onShowPanel(){
				console.log("准备调用chooseLocation")
				const _this = this;
				uni.chooseLocation({
					success(res) {
						console.log("调用chooseLocation成功")
						_this.value = res.address
						_this.$emit('change', {
							detail: res,
							currentTarget: {
								dataset: {
									type: _this.type
								}
							}
						})
					},
					fail(e) {
						console.log("调用chooseLocation失败：" + e.errMsg)
						if(e.errMsg === 'chooseLocation:fail auth deny'){
							uni.navigateTo({
								url:'../../pages/get-rights/get-rights?type=chooseLocation'
							})
							// Dialog.confirm({
							//   title: '授权提示',
							//   message: '没有地图访问权限，前去授权',
							//   confirmButtonText: '授权',
							//   cancelButtonText: '取消'
							// }).then(() => {
							// 	console.log(1111111112)
							//   uni.openSetting({
							//     success (res) {
							//       console.log(res.authSetting)
							//     }
							//   })
							// }).catch(() => {
							//   // on cancel
							// });
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
